/**
 * 
 */
package com.module.osr.engine;

import java.io.InputStream;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.dalonedrau.jogl.engine.GameApplet;
import com.dalonedrau.jogl.engine.GameController;
import com.dalonedrau.xmlparser.XMLParserUtility;

/**
 * Utility class to initialize game data.
 * @author Donald
 */
public final class Init {
	/** the one and only instance of the <code>GameController</code> class. */
	private static Init	instance;
	/**
	 * Gives access to the singleton instance of {@link GameController}.
	 * @return {@link GameController}
	 */
	public static Init getInstance() {
		if (Init.instance == null) {
			Init.instance = new Init();
		}
		return Init.instance;
	}
	/** Loads the game fonts. */
	private static void loadFonts() {
		String mapURL = "com/cob/dat/fonts.xml";
		InputStream is =
				Init.class.getClassLoader().getResourceAsStream(mapURL);
		Document serviceDoc = XMLParserUtility.getInstance().parseXmlFile(is);
		Init.parseFonts(serviceDoc);
	}
	/**
	 * Parses an xml document.
	 * @param dom the xml document
	 */
	private static void parseFonts(final Document dom) {
		try {
			Element docEle = dom.getDocumentElement();
			// get a nodelist of mapHex elements
			NodeList nl = docEle.getElementsByTagName("font");
			if (nl != null && nl.getLength() > 0) {
				for (int i = 0; i < nl.getLength(); i++) {
					Element element = (Element) nl.item(i);
					String name =
							XMLParserUtility.getInstance().getTextFromElement(
									element, "name");
					int point =
							XMLParserUtility.getInstance().getIntValue(
									element, "point");
					// GameFont font = new GameFont(name, point);
				}
			}
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
	}
	/** Hidden constructor. */
	private Init() {}
	/**
	 * Initializes all game data.
	 * @throws Exception if an error occurs
	 */
	public void initGameData() throws Exception {}
}
